﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Validation;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using NhaThuocOnline.Entities;

namespace NhaThuocOnline.Repositories
{
    public class BenhNhanRepository:IDisposable
    {
        QLNhathuocContext context = new QLNhathuocContext();
        public void InsertOrUpdate(BenhNhan benhnhan)
        {
            if (benhnhan.Id == default(int))
            {
                context.BenhNhans.Add(benhnhan);
            }
            else
            {
                context.Entry(benhnhan).State = EntityState.Modified;
            }
        }
        public void Delete(int id)
        {
            BenhNhan benhnhan = context.BenhNhans.Find(id);
            context.BenhNhans.Remove(benhnhan);
        }
        public void Save()
        {
            context.SaveChanges();
        }
        public void Dispose()
        {
            context.Dispose();
        }
        public BenhNhan Find(int id)
        {
            return context.BenhNhans.Find(id);
        }
        //Get all bacsi in bang Bacsis
        public IQueryable<BenhNhan> GetAll
        {
            get { return context.BenhNhans; }
        }

    }
}
